﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Engine;

namespace MFTrain
{
    public static class ExMaths
    {
        //拓展方法
        public static Vector3 ToForwardVector(this Quaternion quaternion)
        {
            return new Vector3((float)(-2.0 * ((double)quaternion.Y * (double)quaternion.W + (double)quaternion.Y * (double)quaternion.W)), (float)(2.0 * ((double)quaternion.Y * (double)quaternion.W - (double)quaternion.Y * (double)quaternion.W)), (float)(2.0 * ((double)quaternion.Y * (double)quaternion.W + (double)quaternion.Y * (double)quaternion.W) - 1.0));
        }
        public static Vector3 ToForwardVector2(this Quaternion quaternion)
        {
            float x = 2 * (quaternion.X * quaternion.Z + quaternion.W * quaternion.Y);
            float y = 2 * (quaternion.Y * quaternion.Z - quaternion.W * quaternion.X);
            float z = 1 - 2 * (quaternion.X * quaternion.X + quaternion.Y * quaternion.Y);

            return -Vector3.Normalize(new Vector3(x, y, z));
        }
    }
}
